import store from "store/store"
import axios from "axios";
const apiAxios = axios.create({
    baseURL:"/api"
})

import NProgress from "nprogress"
// 添加请求拦截器
apiAxios.interceptors.request.use(function (config) {
    //开启进度条
    NProgress.start();
    //带上了UUID
    if(store.state.user.UUID){
        config.headers.userTempId = store.state.user.UUID;
    }
    //带上Token
    if(store.state.user.token){
        config.headers.token = store.state.user.token;
    }
    return config;
});

// 添加响应拦截器
apiAxios.interceptors.response.use(function (response) {
    //关闭进度条
    NProgress.done()
    return response.data;
}, function (error) {
    //关闭进度条
    NProgress.done()
    return Promise.reject(error);
});

export default apiAxios